package guoanmaker.operator.business.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.model.ResidueCount;
import guoanmaker.operator.business.repository.OperatorResidueCountRepository;

@Service
public class OperatorResidueCountService {

	@Autowired
	private OperatorResidueCountRepository repository;

	public void patentSearchMinusOne() {
		if (repository.getPatentSearch().getResidueCount() > 0) {
			repository.patentSearchMinusOne();
		}
	}

	public void patentInfoSearchMinusOne() {
		if (repository.getPatentSearchInfo().getResidueCount() > 0) {
			repository.patentInfoSearchMinusOne();
		}
	}

	public Map<String, Object> patentSearchDetail() {
		int temp = 0;
		ResidueCount residueCount = repository.getPatentSearch();
		ResidueCount residueInfoCount = repository.getPatentSearchInfo();
		Map<String, Object> map = new HashMap<>();
		map.put("count", (temp = residueCount.getResidueCount()) >= 0 ? temp : 0);
		map.put("lastTime", residueCount.getLastQueryDate());
		temp = 0;
		map.put("countInfo", (temp = residueInfoCount.getResidueCount()) >= 0 ? temp : 0);
		map.put("lastInfoTime", residueInfoCount.getLastQueryDate());
		return map;
	}

	public Map<String, Object> patentSearchInfoDetail() {
		int temp = 0;
		ResidueCount residueCount = repository.getPatentSearchInfo();
		Map<String, Object> map = new HashMap<>();
		map.put("count", (temp = residueCount.getResidueCount()) >= 0 ? temp : 0);
		map.put("lastTime", residueCount.getLastQueryDate());
		return map;
	}
}
